package com.self.baseutile;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.WindowManager;

import androidx.annotation.NonNull;



import com.self.baseutile.Utile.Cockroach;
import com.self.baseutile.Utile.SharedPreferencesUtil;
import com.hjq.toast.ToastUtils;


/**
 * Craeted by: huangdx
 * Date : 2021/2/23
 * Describe :
 */
public class MRWApplication extends Application    {

    public static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
     //   MultiDex.install(this);
        mContext = this;
//             ARouter.openLog();//打开日志
//       //     ARouter.openDebug();//打开调式模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
//         ARouter.init(this);
         ToastUtils.init(this);
         mContext = this;
         Cockroach.install(new Cockroach.ExceptionHandler() {//防止闪退
            @Override
            public void handlerException(final Thread thread, final Throwable throwable) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Log.e("AndroidRuntime","--->CockroachException:"+thread+"<---",throwable);
                            com.self.baseutile.components.ToastUtils.Errorshow("Exception Happend\n" + thread + "\n" + throwable.toString());
                        } catch (Throwable e) {

                        }
                    }
                });
            }
        });

    }


    private static int SCREEN_HEIGHT = 0;
    private static int SCREEN_WIDTH = 0;
    public static int getScreenWidth(@NonNull Context context) {
        if (SCREEN_WIDTH == 0) {
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            SCREEN_WIDTH = wm.getDefaultDisplay().getWidth();
        }
        return SCREEN_WIDTH;
    }
    public static int getScreenHeight(@NonNull Context context) {
        if (SCREEN_HEIGHT == 0) {
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            SCREEN_HEIGHT = wm.getDefaultDisplay().getHeight();
        }
        return SCREEN_HEIGHT;
    }
}
